﻿using Microsoft.AspNetCore.Mvc;
using PMS.Services.SharedKernel;
using PMS.Web.Factories.Customers;
using PMS.Web.Framework.Controllers;
using PMS.Web.Models.Customers;

namespace PMS.Web.Controllers.Backend.BackendHome
{
    public class BackendHomeController : BaseAdminController
    {
        #region Fields
        private readonly IWorkContext _workContext;
        private readonly ICustomerModelFactory _customerModelFactory;
        #endregion

        public BackendHomeController(IWorkContext workContext,
            ICustomerModelFactory customerModelFactory)
        {
            _workContext = workContext;
            _customerModelFactory = customerModelFactory;
        }

        public virtual IActionResult Home()
        {
            ViewBag.PageTitle = "Welcome to PMSWeb AdminPanel - Good Luck!";
            ViewBag.BodyHtmlClass = "layui-layout-body pear-admin";
            var customer = _workContext.CurrentCustomer;
            if (customer == null || customer.IsDeleted)
                return new RedirectToActionResult("ErrorPage", "Common", new { errmsg = "指定用户不存在或已被注销" }, false);

            CustomerModel model = _customerModelFactory.PrepareCustomerModel(null, customer);
            return View(model);
        }

        public virtual IActionResult Index()
        {
            ViewBag.PageTitle = "后台首页";
            ViewBag.BodyHtmlClass = "pear-container";
            return View();
        }
    }
}
